//
//  ClusterLightScene.h
//  Ray Tracer
//
//  Created by Kaila, Ashish on 4/5/13.
//  Copyright (c) 2013 Kaila, Ashish. All rights reserved.
//

#ifndef Ray_Tracer_ClusterLightScene_h
#define Ray_Tracer_ClusterLightScene_h

void renderClusterLightScene(Raytracer& raytracer,
                             int width,
                             int height,
                             bool enableSpecular)
{
    // Camera parameters.
	Point3D eye(0, 0, 7);
	Vector3D view(0, 0, -1);
	Vector3D up(0, 1, 0);
	double fov = 40;
    
    /*
     SolidMaterial(Colour ambient,
     Colour diffuse,
     Colour specular,
     double specularExp,
     double diffuseReflectivityFactor,
     double specularReflectivityFactor,
     double refractiveIndex);
     */
    
	// Defines a material for shading.
	SolidMaterial planeMaterial(Colour(0.83137254901961, 0.83137254901961, 0.83137254901961),
                                Colour(0.83137254901961, 0.83137254901961, 0.83137254901961),
                                Colour(0.3, 0.3, 0.3),
                                10,
                                0,
                                1,
                                0);
    
    SolidMaterial redMaterial (Colour(0.23529411764706, 0, 0),
                               Colour(0.23529411764706, 0, 0),
                               Colour(0.508273, 0.508273, 0.508273),
                               80,
                               1,
                               0.5,
                               0);
    
    SolidMaterial greenMaterial(Colour(0, 0, 0),
                                Colour(0.13725490196078, 0.23137254901961, 0.12941176470588),
                                Colour(0.1, 0.1, 0.1),
                                100,
                                0.5,
                                0,
                                1.66);
    
    
    SolidMaterial blueMaterial(Colour(0.02352941176471, 0.03137254901961, 0.46666666666667),
                               Colour(0.02352941176471, 0.03137254901961, 0.46666666666667),
                               Colour(0.316228, 0.316228, 0.316228),
                               10,
                               0.5,
                               0.3,
                               0);
    
    blueMaterial.setGlossFactor(20);
    
	// Defines a point light source.
    double area = 8;
    double intensity = 0.35;
	raytracer.addLightSource( new ClusterLight(Point3D(2.5, 6, 0),
                                              Vector3D(area, 0, 0),
                                              Vector3D(0, area, 0),
                                              2,
                                              Colour(intensity, intensity, intensity) ),
                             enableSpecular);
    
    raytracer.addLightSource( new ClusterLight(Point3D(-2.5, 6, 0),
                                              Vector3D(area, 0, 0),
                                              Vector3D(0, area, 0),
                                              2,
                                              Colour(intensity, intensity, intensity) ),
                             enableSpecular);
    
	SceneDagNode* plane = raytracer.addObject( new UnitSquare(&planeMaterial));
	SceneDagNode* red_sphere = raytracer.addObject( new UnitSphere(&redMaterial));
    SceneDagNode* green_sphere = raytracer.addObject( new UnitSphere(&greenMaterial));
    SceneDagNode* blue_sphere = raytracer.addObject( new UnitSphere(&blueMaterial));
    
	// Apply some transformations to the unit square.
	double factor1[3] = { 80, 80, 80 };
    double factor2[3] = { 1.5, 1.5, 1.5 };
    double factor3[3] = { 2, 2, 2 };
    double factor4[3] = {0.75, 0.75, 0.75};
    
    SceneObject* planeObj = plane->obj;
	planeObj->translate(Vector3D(0, -2, -9));
	planeObj->scale(Point3D(0, 0, 0), factor1);
    planeObj->rotate('x', -90);
    
    SceneObject* redSphereObj = red_sphere->obj;
    redSphereObj->scale(Point3D(0, 0, 0), factor2);
    redSphereObj->translate(Vector3D(-1.5, 0.5, -2));
    redSphereObj->rotate('x', -75);
    
    SceneObject* greenSphereObj = green_sphere->obj;
    greenSphereObj->scale(Point3D(0,0,0), factor3);
    greenSphereObj->translate(Vector3D(1, 0, -1));
    greenSphereObj->rotate('x', -75);
    
    SceneObject* blueSphereObj = blue_sphere->obj;
    blueSphereObj->scale(Point3D(0,0,0), factor4);
    blueSphereObj->translate(Vector3D(-1, -1.5, 1));
    blueSphereObj->rotate('x', -75);
    
	// Render the scene, feel free to make the image smaller for
	// testing purposes.
	raytracer.render(width, height, eye, view, up, fov, "cluster1.bmp");
	
	// Render it from a different point of view.
    //Point3D eye2(4, 2, 1);
	//Vector3D view2(-4, -2, -6);
	//raytracer.render(width, height, eye2, view2, up, fov, "final2.bmp");
}


#endif
